<template>
  <view class="content">
    <view class="inform flex_between">
      <u-notice-bar
        :text="promptList"
        color="#FF6161"
        mode="horizontal"
      ></u-notice-bar>
    </view>
    <view class="line"></view>

    <!-- 聊天内容 -->
    <scroll-view
      :style="{ height: scrollViewHeight }"
      @tap="hideKeyboard()"
      class="chat"
      scroll-y="true"
      scroll-with-animation="true"
      :scroll-into-view="scrollToView"
      :scroll-with-animation="true"
    >
      <view class="location" v-if="quizData.uid != userInfo.id">
        <u-icon
          class="icon2"
          name="map-fill"
          size="16"
          color="#9C9C9C"
        ></u-icon>
        <view class="icon3">{{ userInfo.city }}</view>
      </view>
      <view class="chat_main" :style="{ paddingBottom: inputHeight + 'rpx' }">
        <view
          class="chat_record"
          v-for="(item, index) in curMessageList"
          :key="index"
          :id="'msgItem' + item.timestamp"
        >
          <!-- 时间 -->
          <view class="chat_time" v-if="item.add_time != ''">
            {{ changeTime(item.timestamp) }}
          </view>

          <!-- 对方撤回 -->
          <view
            class="msg_revoke"
            v-if="
              item.extendedData.id == userInfo.id &&
              item.extendedData.msgRevoke == 1
            "
            >你撤回了一条消息
          </view>

          <!-- 自己撤回 -->
          <view
            class="msg_revoke"
            v-if="
              item.extendedData.id != userInfo.id &&
              item.extendedData.msgRevoke == 1
            "
          >
            "{{ item.extendedData.nickname }}"撤回了一条消息</view
          >

          <!-- 左边（对方发来的消息） -->
          <view
            class="msg_m msg_left"
            v-if="
              item.extendedData.id != userInfo.id &&
              item.extendedData.msgRevoke == 0
            "
          >
            <!-- 对方头像 -->
            <image
              class="user_img"
              :src="getAvatar(item.extendedData.id)"
              mode="aspectFill"
            >
            </image>
            <image
              class="v-img"
              v-if="
                (quizData.quiz_is_major == 1 &&
                  item.extendedData.id == quizData.uid) ||
                (quizData.ans_is_major == 1 &&
                  item.extendedData.id == quizData.ans_uid)
              "
              src="https://xzcs-public-files.oss-cn-beijing.aliyuncs.com/static/csjh/img/V.png"
            >
            </image>
            <view>
              <view class="user_name">
                <text>{{ getNickname(item.extendedData.id) }}</text>
              </view>

              <view class="message message_left">
                <!-- 文字 -->

                <view @longpress="longpress">
                  <u-tooltip
                    class="msg_text"
                    :text="item.message"
                    :buttons="['引用', '举报']"
                    v-if="item.extendedData.type == 1"
                    @click="
                      (e) => {
                        clickTip1(e, item);
                      }
                    "
                  >
                  </u-tooltip>
                </view>

                <!-- 图片 -->
                <image
                  v-if="item.extendedData.type == 11"
                  @tap="previewImg(item.message)"
                  :src="item.message"
                  class="msg_img"
                  mode="widthFix"
                ></image>

                <!-- 表情 -->
                <image
                  v-if="item.extendedData.type == 111"
                  :src="item.message"
                  class="msg_emoji"
                  mode="widthFix"
                ></image>
              </view>

              <!-- 引用的消息展示 -->
              <view
                v-if="item.extendedData.quoteMsg != null"
                class="quote_msg_left"
              >
                <text class="txt_item ellipsis2">
                  {{ item.extendedData.quoteMsg.nickname }}:{{
                    item.extendedData.quoteMsg.message
                  }}</text
                >
              </view>
            </view>
          </view>

          <!-- 右边（自己发出的消息） -->
          <view
            class="msg_m msg_right"
            v-if="
              item.extendedData.id == userInfo.id &&
              item.extendedData.msgRevoke == 0
            "
          >
            <!-- 自己头像 -->
            <image
              class="user_img"
              :src="getAvatar(item.extendedData.id)"
              mode="aspectFill"
            ></image>
            <image
              class="v-img"
              v-if="
                (quizData.quiz_is_major == 1 &&
                  item.extendedData.id == quizData.uid) ||
                (quizData.ans_is_major == 1 &&
                  item.extendedData.id == quizData.ans_uid)
              "
              src="https://xzcs-public-files.oss-cn-beijing.aliyuncs.com/static/csjh/img/V.png"
            >
            </image>
            <view>
              <view class="user_name">
                <text>{{ getNickname(item.extendedData.id) }}</text>
              </view>
              <view class="message message_right">
                <!-- 文字 -->
                <view @longpress="longpress">
                  <u-tooltip
                    class="msg_text"
                    :text="item.message"
                    :buttons="claActionMenu(item)"
                    v-if="item.extendedData.type == 1"
                    @click="
                      (e) => {
                        clickTip(e, item);
                      }
                    "
                  >
                  </u-tooltip>
                </view>

                <!-- 图片 -->
                <image
                  v-if="item.extendedData.type == 11"
                  @tap="previewImg(item.message)"
                  :src="item.message"
                  class="msg_img"
                  mode="widthFix"
                ></image>

                <!-- 表情 -->
                <image
                  v-if="item.extendedData.type == 111"
                  :src="item.message"
                  class="msg_emoji"
                  mode="widthFix"
                ></image>
              </view>

              <!-- 引用消息展示 -->
              <view
                v-if="item.extendedData.quoteMsg != null"
                class="quote_msg_right"
              >
                <text class="txt_item ellipsis2">
                  {{ item.extendedData.quoteMsg.nickname }}:{{
                    item.extendedData.quoteMsg.message
                  }}</text
                >
              </view>

              <!-- 已读未读 -->
              <view class="read c1C8" v-if="item.receiptStatus == 1">未读</view>
              <view class="read c999" v-if="item.receiptStatus == 2">已读</view>
            </view>
          </view>
        </view>

        <view class="tips" v-if="showText">
          {{ wenda_reminder }}
        </view>
        <view class="tips" v-if="showText1">
          正在为您匹配老师，预计1分钟，请耐心等待</view
        >

        <view class="tips" v-if="showText2">
          当前为非工作时段，可能无法及时为您匹配到老师，烦请谅解</view
        >

        <view v-if="showText3" class="tips"
          >您好，如还有问题请及时与老师沟通，如无问题请点击结束，否则，系统将在1分钟后默认该解答结束。</view
        >

        <!-- 问题已结束 -->
        <view class="service_end">
          <view class="sd_tips" v-if="showText4">问题已结束</view>
          <view
            class="sd_evaluate"
            v-if="
              quizData.is_satisfied == 0 &&
              quizData &&
              quizData.status == 3 &&
              quizData.uid == userInfo.id
            "
          >
            <view class="flex_center">
              <u-icon name="volume" color="#2979ff"></u-icon>
              <text class="ml10 c-333">您对我的服务满意吗？</text>
            </view>
            <view class="choose_btn">
              <view
                class="flex_center_align"
                @click="satisfied(false)"
                :class="btnActive == 1 ? 'active_btn' : 'btn_left'"
              >
                不满意
              </view>
              <view
                class="flex_center_align"
                @click="satisfied(true)"
                :class="btnActive == 0 ? 'active_btn' : 'btn_left'"
              >
                满意
              </view>
            </view>
            <view class="sd_reason" v-if="unSatisfied">
              <textarea
                class="sd_input"
                v-model="reasonMsg"
                placeholder="您需要提交不满意的原因，后面会给您合理的答案"
              ></textarea>
              <view class="sb_btn" @click="submitReason()"> 提交 </view>
            </view>
          </view>
        </view>
      </view>
      <view class="perch"></view>
    </scroll-view>

    <!-- 输入框 -->
    <view class="submit_send" :style="{ bottom: bottomVal }">
      <view class="flex">
        <view
          v-if="quizData && quizData.uid == userInfo.id && quizData.status == 2"
          class="endChat"
          @click="endChat = true"
        >
          结束对话</view
        >
        <view
          class="endChat"
          @click="stopAnswer(isStop ? 0 : 1)"
          v-if="quizData.uid != userInfo.id && quizData.status == 2"
        >
          {{ isStop == 0 ? "暂停" : "已暂停" }}
        </view>
      </view>
      <submit
        ref="submit"
        @inputs="inputs"
        @heights="heights"
        @clickSend="clickSend"
        @changeBottomVal="changeBottomVal"
        :oftenList="oftenList"
        :showOftenMsg="showOftenMsg"
        :isInputFocus="isInputFocus"
      >
      </submit>
    </view>

    <!-- 确认结束对话 -->
    <u-modal
      ref="endChat"
      :show="endChat"
      showCancelButton
      @cancel="endChat = false"
      cancelText="取消"
      content="确定要结束服务吗？"
      confirmText="确定"
      confirmColor="#1C87F3"
      @confirm="
        closeAsk();
        endChat = false;
      "
      width="500rpx"
    >
    </u-modal>

    <!-- 评价弹出层 -->
    <u-popup
      ref="evaluateShow"
      :show="evaluateShow"
      :round="15"
      closeable
      @close="evaluateShow = false"
      :closeOnClickOverlay="true"
    >
      <view class="evaluateShow">
        <text class="evaluateShow_title">您的评价是老师进步的动力</text>
        <u-rate
          size="40"
          :count="count"
          v-model="starValue"
          active-color="#ffc847"
          inactive-color="#b2b2b2"
          gutter="20"
        >
        </u-rate>
        <view class="comment_con">
          <view class="comTxt1">{{ showTitle(starValue) }}</view>
          <view class="items" v-if="starValue == 1">
            <view
              class="item"
              :class="item.checked ? 'active' : ''"
              v-for="(item, index) in itemTxtList1"
              :key="index"
              @click.stop="chooseItem(item, index)"
            >
              {{ item.name }}
            </view>
          </view>
          <view class="items" v-if="starValue == 2">
            <view
              class="item"
              :class="item.checked ? 'active' : ''"
              v-for="(item, index) in itemTxtList2"
              :key="index"
              @click.stop="chooseItem(item, index)"
            >
              {{ item.name }}
            </view>
          </view>
          <view class="items" v-if="starValue == 3">
            <view
              class="item"
              :class="item.checked ? 'active' : ''"
              v-for="(item, index) in itemTxtList3"
              :key="index"
              @click.stop="chooseItem(item, index)"
            >
              {{ item.name }}
            </view>
          </view>
          <view class="items" v-if="starValue == 4">
            <view
              class="item"
              :class="item.checked ? 'active' : ''"
              v-for="(item, index) in itemTxtList4"
              :key="index"
              @click.stop="chooseItem(item, index)"
            >
              {{ item.name }}
            </view>
          </view>
          <view class="items" v-if="starValue == 5">
            <view
              class="item"
              :class="item.checked ? 'active' : ''"
              v-for="(item, index) in itemTxtList5"
              :key="index"
              @click.stop="chooseItem(item, index)"
            >
              {{ item.name }}
            </view>
          </view>
        </view>
        <textarea
          auto-height="true"
          class="comment_input"
          v-model="inputTxt"
          placeholder="您的评价是对答主最好的鼓励"
        ></textarea>
        <view class="submit" @click.stop="evaluate">提交评价</view>
      </view>
    </u-popup>

    <!-- 举报弹出层 -->
    <u-popup
      :show="reportPopup"
      @close="closeReport"
      mode="bottom"
      :round="10"
      :closeable="true"
    >
      <view class="reportContent">
        <view class="reportTitle">举报消息</view>
        <view
          class="li"
          @click="onClickReport(item)"
          v-for="(item, index) in reportType"
          :key="item.id"
        >
          {{ item.type }}
        </view>
      </view>
    </u-popup>

    <!-- 完成任务弹窗 -->
    <pointsTips
      v-if="showPointsTips"
      :title="pointsTipsTitle"
      :points="points"
    ></pointsTips>
  </view>
</template>

<script
  type="text/javascript"
  src="plus-confusion://../quiz/chatRoom/index"
></script>

<style lang="scss">
.content {
  height: 100vh;
  background-color: rgba(244, 244, 244, 1);
  position: relative;
}

.inform {
  position: fixed;
  z-index: 100;
  width: 750rpx;
  height: 69rpx;
  background: #fff9ea;
  color: #c7b27c;
  font-size: 26rpx;
}

.chat {
  .chat_main {
    padding-left: 32rpx;
    padding-right: 32rpx;
    padding-top: 20rpx;
    display: flex;
    flex-direction: column;
  }

  .chat_record {
    .msg_revoke {
      margin: 0 auto;
      color: #a4a4a4;
      font-size: 26rpx;
      text-align: center;
    }

    .chat_time {
      margin-top: 60rpx;
      font-size: 24rpx;
      color: rgba(39, 40, 50, 0.3);
      line-height: 34rpx;
      padding: 10rpx 0rpx;
      text-align: center;
    }

    .msg_m {
      display: flex;
      padding: 20rpx 0;

      .user_img {
        flex: none;
        width: 80rpx;
        height: 80rpx;
        border-radius: 50%;
      }

      .message {
        flex: none;
        max-width: 480rpx;
      }

      .msg_text {
        display: inline-block;
        font-size: 32rpx;
        color: rgba(39, 40, 50, 1);
        line-height: 44rpx;
        padding: 18rpx 24rpx;
        max-width: 480rpx;
      }

      .msg_img {
        max-width: 260rpx;
        border-radius: 20rpx;
      }

      .msg_emoji {
        width: 200rpx;
        height: 200rpx;
      }

      .user_name {
        flex: none;
        margin-bottom: 13rpx;
        font-size: 24rpx;
        color: #333;
      }
    }

    .msg_left {
      position: relative;
      flex-direction: row;

      .msg_text {
        margin-left: 16rpx;
        background-color: #fff;
        border-radius: 0rpx 20rpx 20rpx 20rpx;
      }

      .msg_img {
        margin-left: 16rpx;
      }

      .user_name {
        margin-left: 16rpx;
      }

      .v-img {
        position: absolute;
        left: 57rpx;
        top: 76rpx;
        width: 26rpx;
        height: 26rpx;
      }
    }

    .msg_right {
      position: relative;
      flex-direction: row-reverse;

      .msg_revoke {
        margin: 0 auto;
        margin-top: 60rpx;
        color: #a4a4a4;
        font-size: 26rpx;
      }

      .msg_text {
        display: flex;
        justify-content: flex-end;
        margin-right: 16rpx;
        background-color: #ddeeff;
        border-radius: 20rpx 0rpx 20rpx 20rpx;
      }

      .msg_img {
        margin-right: 16rpx;
      }

      .user_name {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        margin-right: 16rpx;
      }

      .v-img {
        position: absolute;
        right: 0;
        top: 76rpx;
        width: 26rpx;
        height: 26rpx;
      }
    }
  }

  .tips {
    margin: 0 auto;
    margin-top: 60rpx;
    padding: 20rpx 40rpx;
    background: #eeeeee;
    border-radius: 112px;
    color: #a4a4a4;
    font-size: 26rpx;
    text-align: center;
  }

  .read {
    position: absolute;
    right: 100rpx;
    bottom: -20rpx;
    font-size: 22rpx;
  }

  .service_end {
    .sd_tips {
      display: flex;
      align-items: center;
      justify-content: center;
      margin: 0 auto;
      margin-top: 100rpx;
      margin-bottom: 35rpx;
      width: 174rpx;
      height: 69rpx;
      background: #ffc847;
      border-radius: 112px;
      font-size: 24rpx;
      color: #fff;
    }

    .sd_evaluate {
      margin: 0 auto;
      padding: 40rpx 70rpx;
      width: 623rpx;
      display: flex;
      flex-direction: column;
      align-items: center;

      .choose_btn {
        display: flex;
        font-size: 26rpx;
        margin: 0 auto;
        margin-top: 50rpx;

        .btn_left {
          width: 227rpx;
          height: 67rpx;
          background: #eeeeee;
          border-radius: 147px;
          margin-right: 33rpx;
          color: #898989;
        }

        .active_btn {
          width: 227rpx;
          height: 67rpx;
          background: #1c87f3;
          border-radius: 147px;
          margin-right: 33rpx;
          color: #f7f7f7;
        }
      }
    }

    .sd_reason {
      position: relative;
      margin-top: 37rpx;
      width: 623rpx;
      height: 320rpx;
      background: #ffffff;
      border-radius: 23px;
      border: 1px solid #dfdfdf;

      .sd_input {
        padding: 30rpx;
        font-size: 24rpx;
      }

      .sb_btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        bottom: 30rpx;
        right: 30rpx;
        width: 129rpx;
        height: 67rpx;
        background: #f1f8ff;
        border-radius: 147rpx;
        border: 1px solid #1c87f3;
        color: #1c87f3;
        font-size: 26rpx;
      }
    }
  }
}

.evaluateShow {
  padding: 100rpx 60rpx;

  .evaluateShow_title {
    margin-bottom: 20rpx;
    font-size: 30rpx;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .comment_con {
    width: 100%;

    .comTxt1 {
      margin: 40rpx auto;
      color: #999;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .items {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      font-size: 24rpx;
      color: #999;
      display: flex;

      .item {
        margin: 0 auto;
        margin: 10rpx;
        width: 181rpx;
        height: 53rpx;
        background: #ffffff;
        border-radius: 147px;
        border: 1px solid #dcdcdc;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      .active {
        background: #1c87f3;
        color: #fff;
      }
    }
  }

  .comment_input {
    margin: 50rpx 0;
    padding: 30rpx;
    background-color: #f3f3f3;
    width: 100%;
    min-height: 120rpx;
    background: #f3f3f3;
    border-radius: 15px;
    font-size: 22rpx;
    color: #999;
  }

  .submit {
    width: 647rpx;
    height: 85rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1c87f3;
    border-radius: 147rpx;
    color: #fff;
  }
}

::v-deep.u-rate {
  margin: 0 auto;
  flex-direction: column-reverse !important;
}

::v-deep.u-modal__content__text {
  flex: none !important;
}

/deep/ .u-count-down__text {
  line-height: 70rpx !important;
  color: #c7b27c !important;
  margin-right: 6rpx;
}

/deep/ .u-tooltip__wrapper__text {
  font-size: 32rpx !important;
  max-width: 400rpx !important;
  white-space: pre-wrap !important;
}

.submit_send {
  width: 100%;
  position: absolute;
  left: 0;
  bottom: 0;
}

.endChat {
  padding: 0 40rpx;
  line-height: 69rpx;
  background: #eeeeee;
  border-radius: 112px;
  color: #a4a4a4;
  font-size: 26rpx;
  max-width: 190rpx;
  margin-left: 10rpx;
}

.message_left {
  display: flex;
  justify-content: flex-start;
}

.message_right {
  display: flex;
  justify-content: flex-end;
}

.quoteMsg {
  display: flex;
  align-items: center;
  margin-left: 30rpx;
  margin-bottom: 20rpx;
  padding: 10rpx;
  font-size: 24rpx;
  color: #999;
  max-width: 480rpx;
  max-height: 82rpx;
  background-color: #e8e8e8;
  border-radius: 10rpx;
}

.quote_msg_left {
  margin-left: 15rpx;
  display: flex;
  align-items: center;
  margin-top: 10rpx;
  padding: 10rpx;
  color: #999;
  max-width: 480rpx;
  max-height: 82rpx;
  background-color: #e8e8e8;
  border-radius: 8rpx;
}

.quote_msg_right {
  margin-right: 15rpx;
  display: flex;
  align-items: center;
  margin-top: 10rpx;
  padding: 10rpx;
  color: #999;
  max-width: 480rpx;
  max-height: 82rpx;
  background-color: #e8e8e8;
  border-radius: 8rpx;
}

.txt_item {
  max-width: 100%;
  max-height: 70rpx;
  line-height: 35rpx;
  font-size: 26rpx;
}

.perch {
  width: 100%;
  height: 100rpx;
}

/deep/ .u-notice-bar {
  background-color: transparent !important;
  padding: 0;
}

.location {
  display: flex;
  align-items: center;
  position: absolute;
  left: 32rpx;
  top: 80rpx;
}

.icon2 {
  width: 20rpx;
}

.icon3 {
  width: auto;
  font-size: 24rpx;
  color: #9c9c9c;
  margin-left: 10rpx;
}

// 举报弹窗样式
.reportContent {
  padding: 20rpx 0;

  .reportTitle {
    font-size: 32rpx;
    color: #333333;
    margin-bottom: 60rpx;
    text-align: center;
    font-weight: bold;
    font-size: 38rpx;
  }

  .li {
    padding: 30rpx 0;
    border-top: 1rpx solid rgba(244, 244, 244, 0.5);
    text-align: center;
  }
}
</style>
